import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import '../../app_files.dart';
import 'widget/config_widget.dart';
import 'action.dart';
import 'state.dart';

Widget buildView(
    OrderViewState state, Dispatch dispatch, ViewService viewService) {

  Widget _infoWidget() => Container(
    padding: EdgeInsets.only(left: 15, right: 15, bottom: 8),
    decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
            bottom: BorderSide(color: ThemeConfig.separeColor, width: 10))),
    child: Column(
      children: [
        Container(
          height: 44,
          child: Align(
            alignment: Alignment.centerLeft,
            child: Text(
              '客户信息',
              style: TextThemeConfig.Font16WithColorBold22,
            ),
          ),
          margin: EdgeInsets.only(bottom: 4),
        ),
        Container(
          padding: EdgeInsets.symmetric(vertical: 5),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                width: 85,
                child:  Text(
                  '客户姓名',
                  style: TextThemeConfig.Font14WithColor66,
                ),
              ),
              Expanded(child: Text(
                state.userInfo.userName ,
                style: TextThemeConfig.Font14WithColor22,
              ),)
            ],
          ),
        ),
        Container(
          padding: EdgeInsets.symmetric(vertical: 6),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                width: 85,
                child:  Text(
                  '客户地址',
                  style: TextThemeConfig.Font14WithColor66,
                ),
              ),
              Expanded(
                child: Text(
                  state.userInfo.userAddress,
                  style: TextThemeConfig.Font14WithColor22,
                ),
              ),
            ],
          ),
        ),
        Container(
          padding: EdgeInsets.symmetric(vertical: 5),
          child: Row(
            children: [
              Container(
                width: 85,
                child: Text(
                  '联系方式',
                  style: TextThemeConfig.Font14WithColor66,
                ),
              ),
              Text(
                state.userInfo.phone,
                style: TextThemeConfig.Font14WithColor22,
              ),
            ],
          ),
        ),
        Container(
          padding: EdgeInsets.symmetric(vertical: 5),
          child: Row(
            children: [
              Container(
                width: 85,
                child: Text(
                  '表号',
                  style: TextThemeConfig.Font14WithColor66,
                ),
              ),
              Text(
                state.userInfo.meterNo,
                style: TextThemeConfig.Font14WithColor22,
              ),
            ],
          ),
        ),
      ],
    ),
  );

  // Widget _gasInfoWidget() => state.items == null
  //     ? Container()
  //     : Container(
  //         padding: EdgeInsets.only(left: 15, right: 15, bottom: 8),
  //         decoration: BoxDecoration(
  //             color: Colors.white,
  //             border: Border(
  //                 bottom:
  //                     BorderSide(color: ThemeConfig.separeColor, width: 10))),
  //         child: Column(
  //           children: [
  //             Container(
  //               height: 44,
  //               child: Align(
  //                 alignment: Alignment.centerLeft,
  //                 child: Text(
  //                   '用气信息',
  //                   style: TextThemeConfig.Font16WithColorBold22,
  //                 ),
  //               ),
  //               margin: EdgeInsets.only(bottom: 4),
  //               decoration: BoxDecoration(
  //                   border: Border(
  //                       bottom: BorderSide(color: ThemeConfig.separeColor))),
  //             ),
  //             Container(
  //               height: 35,
  //               child: Row(
  //                 children: [
  //                   Container(
  //                     width: 123,
  //                     child: Text(
  //                       '表具表底(m³)',
  //                       style: TextThemeConfig.Font14WithColor66,
  //                     ),
  //                   ),
  //                   Expanded(
  //                     child: TextField(
  //                       minLines: 1,
  //                       enabled: false,
  //                       controller: state.gasInfo.meterBaseVolumeController,
  //                       style: TextThemeConfig.Font14WithColor22,
  //                       decoration: InputDecoration(
  //                         border: InputBorder.none,
  //                         hintText: "",
  //                         hintStyle: TextThemeConfig.Font14WithColor99,
  //                         contentPadding: EdgeInsets.only(bottom: 11),
  //                       ),
  //                     ),
  //                   ),
  //                 ],
  //               ),
  //             ),
  //             Container(
  //               height: 35,
  //               child: Row(
  //                 children: [
  //                   Container(
  //                     width: 123,
  //                     child: Text(
  //                       state.userInfo.isICGasUser ? '总购气量(m³)' : '总充值金额(元)',
  //                       style: TextThemeConfig.Font14WithColor66,
  //                     ),
  //                   ),
  //                   Expanded(
  //                     child: TextField(
  //                       minLines: 1,
  //                       enabled: false,
  //                       controller: state.gasInfo.gasBuyTotalController,
  //                       style: TextThemeConfig.Font14WithColor22,
  //                       decoration: InputDecoration(
  //                         border: InputBorder.none,
  //                         hintText: "",
  //                         hintStyle: TextThemeConfig.Font14WithColor99,
  //                         contentPadding: EdgeInsets.only(bottom: 11),
  //                       ),
  //                     ),
  //                   ),
  //                 ],
  //               ),
  //             ),
  //             Container(
  //               height: 35,
  //               child: Row(
  //                 children: [
  //                   Container(
  //                     width: 123,
  //                     child: Row(
  //                       children: [
  //                         Text(
  //                           state.userInfo.isICGasUser ? '当前表底(m³)' : '最后抄表指针',
  //                           style: TextThemeConfig.Font14WithColor66,
  //                         ),
  //                         state.userInfo.isICGasUser ? Text(
  //                           ' *',
  //                           style: TextThemeConfig.Font14WithColorRed,
  //                         ) : Container(),
  //                       ],
  //                     ),
  //                   ),
  //                   Expanded(
  //                     child: TextField(
  //                       minLines: 1,
  //                       enabled: state.userInfo.isICGasUser ? true : false,
  //                       controller: state.gasInfo.gasUseTotalController,
  //                       style: TextThemeConfig.Font14WithColor22,
  //                       keyboardType:
  //                           TextInputType.numberWithOptions(decimal: true),
  //                       decoration: InputDecoration(
  //                         border: InputBorder.none,
  //                         hintText:
  //                             "请输入${state.userInfo.isICGasUser ? '当前表底' : '最后抄表指针'}",
  //                         hintStyle: TextThemeConfig.Font14WithColor99,
  //                         contentPadding: EdgeInsets.only(bottom: 11),
  //                       ),
  //                       onChanged: (String text) {
  //                         if (state.userInfo.isICGasUser) {
  //                           double value = double.tryParse(text) ?? 0.0;
  //                           double total = double.tryParse(
  //                                   state.gasInfo.gasBuyTotalController.text) ??
  //                               0.0;
  //                           double base = double.tryParse(state
  //                                   .gasInfo.meterBaseVolumeController.text) ??
  //                               0.0;
  //                           String res =
  //                               (total - value + base).toStringAsFixed(4);
  //                           state.gasInfo.gasRemainTotalController.text =
  //                               '${double.tryParse(res)}';
  //                           dispatch(OrderViewActionCreator.onAction());
  //                         }
  //                       },
  //                     ),
  //                   ),
  //                 ],
  //               ),
  //             ),
  //             Container(
  //               height: 35,
  //               child: Row(
  //                 children: [
  //                   Container(
  //                     width: 123,
  //                     child: Text(
  //                       state.userInfo.isICGasUser ? '剩余气量(m³)' : '账户余额(元)',
  //                       style: TextThemeConfig.Font14WithColor66,
  //                     ),
  //                   ),
  //                   Expanded(
  //                     child: TextField(
  //                       enabled: false,
  //                       minLines: 1,
  //                       controller: state.gasInfo.gasRemainTotalController,
  //                       style: TextThemeConfig.Font14WithColor22,
  //                       decoration: InputDecoration(
  //                         border: InputBorder.none,
  //                         hintText: "",
  //                         hintStyle: TextThemeConfig.Font14WithColor99,
  //                         contentPadding: EdgeInsets.only(bottom: 11),
  //                       ),
  //                     ),
  //                   ),
  //                 ],
  //               ),
  //             ),
  //           ],
  //         ));

  Widget _bodyWidget() {
    if (state.items == null) {
      return Container(
        height: 500,
        child: Center(
          child: MyLoadingWidget(),
        ),
      );
    }

    List<Widget> list = state.items.map<Widget>((e) {
      return ConfigWidget(e, dispatch);
    }).toList();
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: list,
    );
  }

  return Scaffold(
    appBar: myAppBar(viewService.context, title: '安检工单',actions: [
      // GestureDetector(
      //   behavior: HitTestBehavior.translucent,
      //   child: Container(
      //     padding: EdgeInsets.only(right: 12),
      //     height: 40,
      //     child: Center(
      //       child: Text(
      //         '历史记录',
      //         style: TextThemeConfig.ActionBarTitle,
      //       ),
      //     ),
      //   ),
      //   onTap: () => CommonUtils.pushRoute(
      //       viewService.context, RoutePath.orderHistoryView,
      //       arguments: {
      //         'account': state.userInfo.userNo,
      //       }),
      // )
    ]),
    body: SafeArea(
      child: GestureDetector(
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              _infoWidget(),
              // _gasInfoWidget(),
              _bodyWidget(),
              Container(
                margin: EdgeInsets.symmetric(horizontal: 15, vertical: 40),
                height: 50,
                decoration: BoxDecoration(
                  color: ThemeConfig.mainColor,
                  borderRadius: BorderRadius.all(Radius.circular(4)),
                ),
                child: InkWell(
                  child: Align(
                    child: Text(
                      '下一步',
                      style: TextThemeConfig.Font16WithWhite,
                    ),
                  ),
                  onTap: () => dispatch(OrderViewActionCreator.onSubmit()),
                ),
              )
            ],
          ),
        ),
        behavior: HitTestBehavior.translucent,
        onTap: () => CommonUtils.closeKey(viewService.context),
      ),
    ),
  );
}
